package com.back.controller;

import com.back.common.utils.Result;
import com.back.security.annotation.RequireRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 求职者控制器
 * 提供求职者专有功能
 */
@RestController
@RequestMapping("/jobseeker")
@Api(tags = "求职者功能接口")
@Slf4j
public class JobSeekerController {

    /**
     * 获取求职者个人资料
     */
    @ApiOperation(value = "获取个人资料")
    @GetMapping("/profile")
    @PreAuthorize("hasRole('JOB_SEEKER')")
    public Result getProfile() {
        return Result.ok().message("获取求职者个人资料成功");
    }

    /**
     * 更新求职者个人资料
     */
    @ApiOperation(value = "更新个人资料")
    @PutMapping("/profile")
    @RequireRole("JOB_SEEKER")
    public Result updateProfile(@RequestBody Object profileData) {
        log.info("求职者更新个人资料: {}", profileData);
        return Result.ok().message("更新求职者个人资料成功");
    }

    /**
     * 获取我申请的职位列表
     */
    @ApiOperation(value = "获取我申请的职位")
    @GetMapping("/applications")
    @RequireRole("JOB_SEEKER")
    public Result getApplications(@RequestParam(required = false, defaultValue = "1") Integer page,
                                  @RequestParam(required = false, defaultValue = "10") Integer size) {
        log.info("获取求职者申请列表, 页码: {}, 每页大小: {}", page, size);
        return Result.ok().message("获取申请列表成功");
    }

    /**
     * 申请职位
     */
    @ApiOperation(value = "申请职位")
    @PostMapping("/apply/{jobId}")
    @RequireRole("JOB_SEEKER")
    public Result applyJob(@PathVariable Long jobId, @RequestParam Long resumeId) {
        log.info("求职者申请职位, 职位ID: {}, 简历ID: {}", jobId, resumeId);
        return Result.ok().message("职位申请成功");
    }

    /**
     * 获取我收藏的职位
     */
    @ApiOperation(value = "获取收藏的职位")
    @GetMapping("/favorites")
    @RequireRole("JOB_SEEKER")
    public Result getFavorites(@RequestParam(required = false, defaultValue = "1") Integer page,
                               @RequestParam(required = false, defaultValue = "10") Integer size) {
        log.info("获取求职者收藏职位, 页码: {}, 每页大小: {}", page, size);
        return Result.ok().message("获取收藏职位成功");
    }

    /**
     * 收藏职位
     */
    @ApiOperation(value = "收藏职位")
    @PostMapping("/favorite/{jobId}")
    @RequireRole("JOB_SEEKER")
    public Result favoriteJob(@PathVariable Long jobId) {
        log.info("求职者收藏职位, 职位ID: {}", jobId);
        return Result.ok().message("职位收藏成功");
    }
}